package com.example.filesynsystem.exception;

import com.example.filesynsystem.enums.ErrorCode;
import com.example.filesynsystem.pojo.Result;

public class BusinessException extends RuntimeException{
    private static long serialVersionUID = 1L;

    private ErrorCode errorCode;
    private String detailMessage;

    public BusinessException() {};
    public BusinessException(ErrorCode errorCode) {this(errorCode,errorCode.getMsg());}
    public BusinessException(ErrorCode errorCode, String detailMessage) {
        super(errorCode.getMsg()+" : "+detailMessage);
        this.errorCode = errorCode;
        this.detailMessage = detailMessage;
    }
    public ErrorCode getErrorCode() {return errorCode;}
    public String getDetailMessage() {return detailMessage;}
    public Result getErrorResult() {
        return Result.BAD().status(errorCode.getHttpStatus()).msg(errorCode.getMsg()).data(detailMessage).build();
    }
}
